<?php
    // Created By : Noan Babao
    // B.S. Computer Science - De La Salle Canlubang
    // Nov 13, 2011

// Start - Checker for those users who will just go to the page by typing directly in the url.

    // INCLUDES CONFIGURATION VARIABLES FOR DATABASE ACCESS
    //include('../includes/siteConfig.php');
     $hostName = "localhost";
    $rootName = "dbasegr";
    $dBasePassword = "dbgr2012";
     $dBaseName = 'greenroute';



    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
     $deptQuery =
                "
                    SELECT departmentId, departmentName
                    FROM Department
                    ORDER BY departmentName
                ";

    $deptResult = mysql_query($deptQuery) or die ('Error in query: $deptQuery. ' . mysql_error());

    // SAVE QUERY RESULTS TO AN ARRAY > $row   
    if (mysql_num_rows($deptResult) > 0){
        while ($row = mysql_fetch_array($deptResult)) {
            $jsondata = array();
            $jsondata['departmentId'] = $row['departmentId'];
            $jsondata['departmentName'] = $row['departmentName'];

            $feed[] = $jsondata;
        }
        mysql_free_result($deptResult);
        mysql_close($connect);
        echo json_encode($feed);
    }
    else
    {
        mysql_free_result($deptResult);
        mysql_close($connect);
        echo json_encode(0);
    }

    
    
    
?>
